/**
 * 入口
 * Created by zengxm on 12/14/2016.
 */

const program = require('commander')
const ProgressBar=require('progress')
const Host = require("./core/host")
const Service = require("./core/service")

program.version("1.0.0")
    .option("-p, progress", "显示进度条");

program
    .command("host [cmd] [datas...]")
    .alias("h")
    .description(Host.description)
    .on("--help",Host.help)
    .option("-i,--ip <ip>", "主机名或者IP地址")
    .option("-p,--port <port>","SSH端口，默认22")
    .option("-u,--user <user>","SSH登录名，默认root")
    .option("-w,--password <password>","SSH登录密码")
    .option("-k,--key <privateKey>","无密登录所用的私钥")
    .option("-a,--all","全部（用于rm等操作）")
    .action(Host.command)
;

//service命令
program.command("service [cmd] [datas...]")
    .alias("s")
    .on("--help",Service.help)
    .option("-i,--information","列出详细信息")
    .option("-a,--all","全部主机")
    .option("-r,--replace","覆盖远程主机上的文件")
    .option("-c,--check","检测服务或者环境")
    .action(Service.command)
;

program.parse(process.argv);
if(program.progress){
    console.log("显示进度条");

    var bar = new ProgressBar('文件上传中 :bar :rate/bps :percent :etas', {
        complete:'\033[42m \033[0m',
        // incomplete:'\u001b[41m \u001b[0m',
        total: 50
    });
    var timer = setInterval(function () {
        bar.tick();
        if (bar.complete) {
            console.log('\ncomplete\n');
            clearInterval(timer);
        }
    }, 50);
}